﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Yxinmt.Windows.Meeting
{
    public class PictureBoxMoveButton
    {
        System.Windows.Forms.PictureBox _PictureBox { get; set; }
        public PictureBoxMoveButton(string imageUrl,int width, int height) {
            _PictureBox = new System.Windows.Forms.PictureBox();
            _PictureBox.Image = Utility.Common.GetDrawingImage(imageUrl);
            _PictureBox.Width = width;  
            _PictureBox.Height = height;
            _PictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;

            _PictureBox.MouseDown += _PictureBox_MouseDown;
            _PictureBox.MouseMove += _PictureBox_MouseMove;
        }

        private void _PictureBox_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
        {
           
        }

        private void _PictureBox_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                Utility.MouseHook.DropMove(_PictureBox.Handle);
                var p2 = Utility.MouseHook.GetCursorPoint();
                Utility.Win32Api.Mouse_Up(p2.X, p2.Y);
            }
        }

        public void Show(int left, int top)
        {
            _PictureBox.Left = left;
            _PictureBox.Top = top;

            Utility.Win32Api.SetParent(_PictureBox.Handle, IntPtr.Zero);
        }

        public void Hide()
        {
            try
            {
                if (_PictureBox != null)
                {
                    _PictureBox.Dispose();
                    _PictureBox = null;
                }
            }
            catch
            {

            }
        }

    }
}
